package zero.tech.redis.delay;

import java.util.Date;

public abstract class RedisDelayedEntity implements Comparable<RedisDelayedEntity>{
	protected long exec_time;
	protected long push_time;
	protected long delay;//单位秒
	public RedisDelayedEntity() {
		super();
	}
	public RedisDelayedEntity(boolean runnow,long delay) {
		super();
		this.delay = delay;
		this.push_time=System.currentTimeMillis();
		if(runnow) {
			this.exec_time=this.push_time;
		}else {
			this.exec_time=this.push_time+this.delay*1000;
		}
	}
	public RedisDelayedEntity(Date now, long delay) {
		this.push_time=now.getTime();
		this.delay = delay;
		this.exec_time=this.push_time+this.delay*1000;
	}
	public long getExec_time() {
		return exec_time;
	}
	public void setExec_time(long exec_time) {
		this.exec_time = exec_time;
	}
	public long getPush_time() {
		return push_time;
	}
	public void setPush_time(long push_time) {
		this.push_time = push_time;
	}
	public long getDelay() {
		return delay;
	}
	public void setDelay(long delay) {
		this.delay = delay;
	}
	@Override
	public int compareTo(RedisDelayedEntity o) {
		return (int) (o.getExec_time()-this.exec_time);
	}
}
